<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>slot插槽的基本使用</title>
  </head>
  <body>
    <!-- 
          1.插槽的基本使用<slot></slot>
          2.插槽的默认值: <slot><button>按钮</button></slot>
          3.如果有多个值，同时放入到组件中进行替换，一起作为替换元素
       -->
    <div id="app">
      <h2>{{message}}</h2>
      <cpn>
        <i>哇呜</i>
        <p>let us eat dinner</p>
        <div>youdao jingpinke</div>
      </cpn>
      <cpn></cpn>
      <cpn><span>haha</span></cpn>
      <cpn><i>yayay</i></cpn>
    </div>
    <template id="cpn">
      <div>
        <h3>我是组件</h3>
        <p>I am a complent</p>
        <!-- 如果<cpn></cpn>中没有使用其他组件占用slot位置，将显示button，如果占用，显示cpn中内容 -->
        <slot><button>按钮</button></slot>
      </div>
    </template>
    <script src="../vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          message: "hello",
        },
        components: {
          cpn: {
            template: "#cpn",
          },
        },
      });
    </script>
  </body>
</html>
